<?php $this->load->view('intro'); ?>
<body id="food_category">
<?php $this->load->view('admin/navigation'); ?>
<div id="edit_section">
<div id="message_block" style="width:600px;""><?php echo $message ?></div>
<form id="main_form" action="index.php/admin/food_category/add" method="post">
  <input type="hidden" value="" id="cat_id" name="cat_id" />
  <label for="category_en_input">Category: </label>
  <input name="en_name" maxlength="64" type="text" id="category_en_input" style="width:150px;" value="" />
  <label for="category_ch_input">Category(CH): </label>
  <input name="ch_name" maxlength="64" type="text" style="width:150px;" id="category_ch_input" value="" />
  <label for="row_select_lable">Row: </label>
  <select name="row_select" id="row_select">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
  </select>
  <label for="column_select_lable">Column: </label>
  <select name="col_select" id="col_select">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
  </select>
  <br /><br />
  <input id="add_form_button" style="display:inline-block; width:140px; height:50px;" type="submit" value="add">
  <input style="display:inline-block; width:140px; height:50px;" type="submit" value="update">
</form>
<br />
<hr style="border:1px solid #CCC;" />
<?php $sequence_opt = ""; ?>

<?php for($i=1; $i<=3; $i++) { ?>
  <?php for($j=1; $j<=5; $j++) { $index = $i . '-' . $j ?>
    <?php if(array_key_exists($index, $food_category) === TRUE) { ?>
      <?php $food = $food_category[$index]; ?>
      <div id="<?php echo $food['id'] ?>" value="<?php echo $food['ch_name']; ?>" class="button"><?php echo $food['ch_name']; ?></div>
      <?php $sequence_opt .= "<option value=\"" . $food['id'] . "_" . $index . "\">" . $index . "</option>"; ?>
      <?php } else { ?>
      <div id="none" style="visibility:hidden;" class="button">empty</div>
    <?php } ?>
  <?php } ?>
<?php } ?>

<form action="index.php/admin/food_category/swap" method="post">
  <select name="swap_from" id="swap_from"><?php echo $sequence_opt; ?></select>
  <select name="swap_to" id="swap_to"><?php echo $sequence_opt; ?></select>
  <input style="display:block; width:140px; height:50px;" type="submit" value="swap category">
</form>
<form action="index.php/admin/food_category/delete" method="post">
  <select name="delete_sequence" id="delete_from"><?php echo $sequence_opt; ?></select>
  <input disable="disable" style="display:block; width:140px; height:50px;" type="submit" value="delete category">
</form>
</div>
<script type="text/javascript">
  $(document).ready(function(){
    $(".button").click(function(){
      $id = $(this).attr("id");
      $data = {target_id:  $id};
      $.ajax({
        type: "POST",
        url: "index.php/admin/food_category/read",
        dataType: "json",
        data: $data,
        success: function(msg){
          $en_name = msg.en_name;
          $ch_name = msg.ch_name;
          $row = msg.sequence[0];
          $col = msg.sequence[2];
          $("#cat_id").val(msg.id);
          $("#category_en_input").val($en_name);
          $("#category_ch_input").val($ch_name);
          $("#row_select").val($row);
          $("#col_select").val($col);
          $("#main_form").attr("action", "index.php/admin/food_category/update");
          $("#add_form_button").attr("disabled", "disabled");
        }
      });
    });
  });

  
</script>
<?php $this->load->view('outro'); ?>
